<?php

require_once 'Zend/Test/PHPUnit/ControllerTestCase.php';

class ControllerTestCase extends Zend_Test_PHPUnit_ControllerTestCase {

    protected $application;
    protected $data;
    protected $_db;

    public function setUp() {
        $this->bootstrap = array($this, 'appBootstrap');
        parent::setUp();
        $this->_db = Zend_Db_Table::getDefaultAdapter();
        $this->LoadData();
    }

    public function appBootstrap() {
        $this->application = new Zend_Application(
                        APPLICATION_ENV, APPLICATION_PATH . '/configs/application.ini'
        );
        $this->application->bootstrap();
    }

    public function LoadData() {
        for ($i = 0; $i < 10; $i++) {
            $this->data['usuario'][$i] = array(
                'Nome' => 'Teste Nome',
                'Login' => 'Teste Login',
                'EMail' => time() + $i . 'teste@teste.com.br',
                'Senha' => '123456',
                'Regra' => 1
            );
        }
    }

    public function RecreateDb() {
        $db = Zend_Db::factory("Pdo_Mysql", array(
                    'host' => 'localhost',
                    'username' => 'root',
                    'password' => '123456',
                    'dbname' => 'imobil_testing'
                ));

        $db->query("DROP DATABASE IF EXISTS `imobil_testing`;");
        $db->query("CREATE DATABASE `imobil_testing`;");
        $db->query("USE `imobil_testing`;");

        $sql = file_get_contents(APPLICATION_PATH . '/../docs/db/initial.sql');
        $db->query($sql);
    }

    public function tearDown() {
        $this->reset();
        $this->resetResponse();
    }

}